const $api = require('./../../utils/request').API;
const filter = require('../../utils/loginCheck');
Page(filter.loginCheck({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    active: '0',
    more: true,
    list: [],
    pageSize: 10,
    pageNum: 1,
  },

  onClick(event) {
    this.setData({
      pageNum: 1,
      active: event.detail.name
    });
    this.getOrderList();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options)
    if (options.type) {
      that.setData({ active: options.type })
    } else {
      that.setData({ active: '0' })
    }
    that.selectComponent('#header').resize();

    this.getOrderList();

  },

  getOrderList() {
    wx.showLoading({
      title: '加载中...',
    })
    let params = {};
    if (this.data.active == 0) {
      params = {
        "openId": wx.getStorageSync('openid') ? wx.getStorageSync('openid') : '',
        "pageNumber": this.data.pageNum,
        "pageSize": this.data.pageSize
      };
    } else {
      params = {
        "openId": wx.getStorageSync('openid') ? wx.getStorageSync('openid') : '',
        "orderState": this.data.active,
        "pageNumber": this.data.pageNum,
        "pageSize": this.data.pageSize
      };
    }
    $api.getOrderList(params).then(res => {
      wx.hideLoading();
      wx.stopPullDownRefresh();
      this.setData({
        list:res.data
      })
    }).catch(err=>{
      wx.stopPullDownRefresh();
      wx.hideLoading();
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

    this.setData({ 
      list: [],
      pageNum:1,
    })
    this.getOrderList();

    // setTimeout(() => {
    //  
    //   wx.hideLoading()
    //   this.setData({ loading: false })
    // }, 3000)
  },

  goDetail(e) {
    wx.navigateTo({
      url: `../orderDetail/orderDetail?detail=${JSON.stringify(e.currentTarget.dataset.detail)}`,
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.more) {
      console.log(1111);
    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
}))